package com.andy.blog.admin.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by andy on 2023/9/17 21:56
 */
@Data
public class TreeSelectDTO implements Serializable {
    private static final long serialVersionUID = 4654590848211331750L;

    /**
     * 节点ID
     */
    private Long id;

    /**
     * 节点名称
     */
    private String label;

    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelectDTO> children;

    public TreeSelectDTO() {
    }

    public TreeSelectDTO(SysMenuDTO sysMenuDTO) {
        this.id = sysMenuDTO.getId();
        this.label = sysMenuDTO.getMenuName();
        this.children = sysMenuDTO.getChildren().stream().map(TreeSelectDTO::new).collect(Collectors.toList());
    }
}
